package ThreadDemo;
/*volatile无法解决两个线程对同一个变量修改带来的线程安全问题*/
class A17{
    public volatile int i=0;
    public void increase(){
        i++;
    }
}

public class ThreadDemo17 {
    public static void main(String[] args) throws InterruptedException {
        A17 a17=new A17();
        Thread t = new Thread() {
            @Override
            public void run() {
                for(int i=0;i<5000;i++) {
                    a17.increase();
                }
            }
        };
        Thread t1 = new Thread() {
            @Override
            public void run() {
                for(int i=0;i<5000;i++) {
                    a17.increase();
                }
            }
        };
        t1.start();
        t.start();
        t1.join();
        t.join();
        System.out.println(a17.i);
    }
}
